package com.example.springbase.test.AutowireMode;

import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * MyImportRegistrar
 *
 * @author zhouxianfeng
 * @date 2021-4-13
 */
public class MyImportRegistrar implements ImportBeanDefinitionRegistrar {


    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        GenericBeanDefinition beanDefinition = (GenericBeanDefinition) registry.getBeanDefinition("userDao1");
        //修改自动注入模型
        beanDefinition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);
        //已经注入了，就不能在重复注入
        //registry.registerBeanDefinition("userDao1", beanDefinition);
    }

}